<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>优家购房系统 - 房屋信息管理</title>
	<!-- 引入css -->
	<link href="css/bootstrap.min.css" rel="stylesheet" />
	<!-- 使用bootstrap前端框架，首先引入jquery -->
	<script type="text/javascript" src="js/jquery-3.3.1.js"></script>
	<!-- 引入js插件 -->
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="css/main.css">
	<link rel="stylesheet" href="lib/font-awesome/css/font-awesome.css">
	<script type="text/javascript">
		$(document).ready(function(){
			//alert(666666)
			var status='${status}';
			//alert(status)
			$("#test option").each(function(){
				if($(this).val()==status){
					$(this).attr("selected",true);
				}
			});
		});
	</script>
	
	
</head>
<body style="background:url('image/bg2.jpg');background-size:cover;">
<div class="box">
	<h3>房屋信息管理</h3>
	<div class="actions">
		<div>
			<a class="btn btn-primary" href="view/house/add.jsp">添加房屋信息</a>
		</div>
		<div>
			<form action="HouseServlet2" method="post">
				<input type="hidden" name="method" value="select">
				所属地区:<input name="area" placeholder="地区名称" value="${area}">
				所属小区:<input name="estate" placeholder="小区名称" value="${estate}">
				房屋面积:<input name="acreage" placeholder="房屋面积" value="${acreage}">
				价格下限:<input name="lowPrice" placeholder="最低价格" value="${lowPrice}">
				价格上限:<input name="highPrice" placeholder="最高价格" value="${highPrice}">
				出租状态:<select name="status" id="test">
							<option value="">请选择</option>
							<option value="2">未出租</option>
							<option value="1">已出租</option>
							<option value="0">停止出租</option>
						</select>
				<button type="submit"><span class="glyphicon glyphicon-search" style="color:red;"></span></button>
			</form>
		</div>
	</div>

	<table class="list">
		<tr>
			<th>序号</th>
			<th>所属地区</th>
			<th>所属小区</th>
			<th>单元号</th>
			<th>所属楼层</th>
			<th>房间号</th>
			<th>面积</th>
			<th>朝向</th>
			<th>限住人数</th>
			<th>出租价格(元)</th>
			<th>出租状态</th>
			<th>操作</th>
		</tr>
		<c:forEach items="${list }" var="house" varStatus="status">
		<tr>
			<td>${status.count }</td>
			<td>${house.h_area }</td>
			<td>${house.h_estate }</td>
			<td>${house.h_unitNumber }</td>
			<td>${house.h_floor }</td>
			<td>${house.h_roomNo }</td>
			<td>${house.h_acreage }</td>
			<td>${house.h_direction }</td>
			<td>${house.h_limit }</td>
			<td>${house.h_price }</td>
			<c:if test="${house.h_status==0 }"><td>停止出租</td></c:if>
			<c:if test="${house.h_status==1 }"><td>已出租</td></c:if>
			<c:if test="${house.h_status==2 }"><td>未出租</td></c:if>
			<td>
				<a title="详情" href="HouseServlet2?method=select&flag=detail&id=${house.h_id }">
				<span class="glyphicon glyphicon-new-window"></span>
				</a>
				&nbsp;&nbsp;
				<a title="编辑" href="HouseServlet2?method=getHouseById&id=${house.h_id }">
				<span class="glyphicon glyphicon-edit"></span>
				</a>
				&nbsp;&nbsp;
				<a title="删除"  onclick="confirmDelete(${house.h_id})">
				<span class="glyphicon glyphicon-remove"></span>				
				</a>
			</td>
		</tr>
		</c:forEach>
	</table>
	<div>
		<c:url value="HouseServlet2?method=select" var="forward">
			<c:param name="pageIndex" value="${pageIndex-1 }"></c:param>
			<c:param name="area" value="${area }"></c:param>
			<c:param name="estate" value="${estate }"></c:param>
			<c:param name="acreage" value="${acreage }"></c:param>
			<c:param name="lowPrice" value="${lowPrice }"></c:param>
			<c:param name="highPrice" value="${highPrice }"></c:param>
			<c:param name="status" value="${status }"></c:param>
		</c:url>
		<c:url value="HouseServlet2?method=select" var="next">
			<c:param name="pageIndex" value="${pageIndex+1 }"></c:param>
			<c:param name="area" value="${area }"></c:param>
			<c:param name="estate" value="${estate }"></c:param>
			<c:param name="acreage" value="${acreage }"></c:param>
			<c:param name="lowPrice" value="${lowPrice }"></c:param>
			<c:param name="highPrice" value="${highPrice }"></c:param>
			<c:param name="status" value="${status }"></c:param>
		</c:url>
	</div>
	<div class="pager-info">
		<div>共有 ${totalCounts } 条记录，第 ${pageIndex }/${totalPages } 页 </div>
		<div>
			<ul class="pagination" style="list-style:none;">
				<li class="paginate_button previous disabled }">
				<c:if test="${pageIndex > 1 }">
					<a href="${forward }">上一页</a>
				</c:if>
				</li>
				<li class="paginate_button active">
					<form action="HouseServlet2?method=select" method="post">
					<input type="hidden" name="area" value="${area }">
					<input type="hidden" name="estate" value="${estate }">
					<input type="hidden" name="acreage" value="${acreage }">
					<input type="hidden" name="lowPrice" value="${lowPrice }">
					<input type="hidden" name="highPrice" value="${highPrice }">
					<input type="hidden" name="status" value="${status }">
					<input name="pageIndex">
					<input type="submit" value="跳转">
					</form>
				</li>
				<li class="paginate_button next disabled">
					<c:if test="${pageIndex < totalPages }">
				<a href="${next }">下一页</a>
				</c:if>
				</li>
			</ul>
		</div>
	</div>
</div>
<script src="lib/jquery/jquery.js"></script>
<script>
function confirmDelete(id){
	if (confirm("确定要删除码？")) {
		window.location="HouseServlet2?method=delete&id="+id;
		return true;
	}
	return false;
}
</script>
</body>
</html>